import 'package:flutter/material.dart';
import 'package:flutter_common/ui/widget/text.dart';

import '../../flutter_common.dart';
import '../../util/context_extension.dart';

class TextCheckBox extends StatelessWidget {

  final Color? backgroundColor;
  final String name;
  final Widget? nameWidget;

  ///name字体颜色
  final Color? color;
  final bool circleShape;
  final Function()? onTap;

  final double? fontSize;
  final bool showLine;
  final bool? value;
  final ValueChanged<bool?>? onChanged;

  final CrossAxisAlignment crossAxisAlignment;

  ///通过修改padding 改变默认高度
  final EdgeInsetsGeometry namePadding;
  final EdgeInsetsGeometry linePadding;

  final TextAlign textAlign;
  final TextStyle? contentStyle;

  const TextCheckBox({
    super.key,
    this.name = "",
    this.value,
    this.circleShape = false,
    this.onChanged,
    this.fontSize,
    this.onTap,
    this.backgroundColor,
    this.nameWidget,
    this.color = const Color(0xff333333),
    this.showLine = false,
    this.namePadding = const EdgeInsets.fromLTRB(15, 14, 10, 14),
    this.linePadding = const EdgeInsets.fromLTRB(15, 0, 0, 0),
    this.crossAxisAlignment = CrossAxisAlignment.center,
    this.contentStyle,
    this.textAlign = TextAlign.end,
  });
  
  @override
  Widget build(BuildContext context) {
    Widget content = Row(
      crossAxisAlignment: crossAxisAlignment,
      children: [
        Padding(
          padding: namePadding,
          child: nameWidget ??
              Text.rich(TextSpan(
                children: [
                  TextSpan(text: name),
                ],
                style:
                    TextStyle(fontSize: fontSize ?? fontSize28, color: color),
              )),
        ),
        const Spacer(),
        FxCheckBox(value: value, onChanged: onChanged, circleShape: circleShape),
      ],
    );
    if (onTap != null) {
      content = Ink(
          width: double.infinity,
          color: backgroundColor,
          child: InkWell(onTap: () => throttle(onTap), child: content));
    } else if(backgroundColor != null){
      content = Container(color: backgroundColor, child: content);
    }
    return Material(color: Colors.transparent, child: content);
  }
}